# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : p5.py
# @Time     : 2024/5/7 23:24
# @Author   : Robot-Zsj
"""
description:

火星文计算2

https://fcqian.blog.csdn.net/article/details/135398703

i:
7#6$5#12

o:
157

"""
import re

s = input()


def getResult(s):
    p = re.compile("(\\d+)#(\\d+)")

    while True:
        m = p.search(s)
        if m:
            subS = m.group()
            x = int(m.group(1))
            y = int(m.group(2))
            s = s.replace(subS, str(4 * x + 3 * y + 2), 1)
        else:
            break

    arr = list(map(int, s.split('$')))
    x = arr[0]
    for y in arr[1:]:
        x = 2 * x + y + 3
    return x


print(getResult(s))
